#!/usr/bin/perl 
#===============================================================================
#
#         FILE:  conky_stuff.pl
#
#        USAGE:  ./conky_stuff.pl  
#
#  DESCRIPTION: 输出OSS 音量信息，电池信息，音乐播放信息 
#
#      OPTIONS:  ---
# REQUIREMENTS:  oss acpi mpd mpc
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:  razone <zoujichun3166@gmail.com>
#      COMPANY:  
#      VERSION:  
#      CREATED:  2010年09月24日 18时01分17秒
#     REVISION:  ---
#       CODING:  utf8
#===============================================================================

use strict;
use warnings;

my ($conkyout,$mixout,$acpiout,$musicout);
# for mixout
my ($vol) = (`ossmix vol` =~ /:(.*)/);

if ("$vol" eq "0"){
    $mixout = "音量 [静音]";
}else{
    $mixout = "音量 [$vol%]";
}

# for acpiout
my ($acstat) = (`acpi -a` =~ /:\s(.*)/);
my ($bat) = (`acpi -b` =~ /,\s(.*)/);
my ($num) = (`acpi -b` =~ /,\s(.*)%/); # 电量

if ("$acstat" eq "on-line"){
    $acpiout = "电源 [交流电源]";
}elsif ("$acstat" eq "off-line"){
    $bat =~ s/remaining/剩余时间/g;
    $acpiout = "电源 [$bat]";
    if (int($num) lt 10){
        system "xmessage -center Low Battery!";
    }
}

# for musicout
my @mpcstat = `mpc status 2>/dev/null`;
my $song = $mpcstat[0];
chomp($song);
my ($status) = ($mpcstat[1] =~ /(\[.*\])/);
$status =~ s/playing/播放/g;
$status =~ s/paused/暂停/g;
if (defined($song) && defined($status)){
    $musicout = "音乐 $status [$song]";
}else{
    $musicout = "播放器关闭";
}

# for conkyout
print $conkyout = "$acpiout | $mixout | $musicout";
